<template>
  <div>
    <div>分配权限功能</div>
    <el-tree ref="theTree" show-checkbox default-expand-all check-strictly node-key="id" :default-checked-keys="permIds" :data="permissionList" :props="{ label: 'name' }" />
    <el-row class="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button size="small" @click="cancelButton">取 消</el-button>
        <el-button size="small" type="primary" @click="setRolesBtn">确 定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'AssignPermission',
  props: {
    // 所有权限点数据（树形结构）
    permissionList: {
      type: Array,
      default: _ => []
    },
    // 现有权限点id
    permIds: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {}
  },
  watch: {
    permIds() {
      this.$refs.theTree.setCheckedKeys(this.permIds)
    }
  },
  created() {
    // console.log(this.roleId)
  },
  methods: {
    // 取消按钮
    cancelButton() {
      this.$emit('input', false)
    },

    // 设置权限按钮
    setRolesBtn() {
      // 获取现在已选的key对应值形成的数组（权限点id组成的数组）
      this.$emit('addPerEV', this.$refs.theTree.getCheckedKeys())
      this.$emit('input', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  margin-top: 30px;
}
</style>
